<%@ page language="java" import="java.util.*" import="java.text.SimpleDateFormat" pageEncoding="UTF-8"%>
<%@ page import="com.bluesky.light.user.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
	// check if the user is login
	User u = (User)session.getAttribute("user");
	if (u == null) {
		response.sendRedirect("index.jsp");
	}	
	String name = u.getName();
%>
<%
	
	String action = request.getParameter("action");
	
	if (action != null && action.trim().equals("changepwd")) {

		String pwd = request.getParameter("pwd");
		String newpwd = request.getParameter("newpwd");
		if (pwd.trim().equals(u.getPwd())) {
			u.setPwd(newpwd);
			UserService.getInstance().updatePwd(u);
		}
		response.sendRedirect("user_pwdModify.jsp");
		return;
	}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>light - change info</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link href="css/main.css" rel="stylesheet" type="text/css" />
	
	<script language=JavaScript  src="js/checkpassword.js"> 
	</script>

  </head>
  
  <body>
	<!-- header -->
	<div id="header">
		<div id="logo"><img src="images/logo_small2.png"/></div>
	</div>
	<!-- // header -->
	<!-- nav -->
	<div id="nav">
	</div>
	<!-- // nav -->
	<!-- container -->
	<div id="container">
		<!-- contents -->
		<div id="contents">
	    	<div id="menu">
	        	<div>
	        		<div id="user_info">
	            		<img src="develop/user_icon.jpg"/> 
	            		<b>User</b>
	           		</div>
	           		<div>
	           		<%=name%>
	           		</div>
	            </div>
	            <div>
	            	<%SimpleDateFormat sdf = new SimpleDateFormat("EEE, yyyy-MM-dd", new Locale("US"));%><%=sdf.format(new Date())%><br></br>
	            </div>	
	        	<ul>
	            	<li><a href="home.jsp"><img src="images/news.png" /> Health News</a></li>
					<li><a href="user_subscribe.jsp"><img src="images/surscribe.png" /> Appointment</a></li>
					<li><a href="user_history.jsp"><img src="images/account.png" /> Health History</a></li>
					<li><a href="user_hospitalSearchOnMap.jsp"><img src="images/photo.png" /> Searching Hospital</a></li>
						                <li><a href="user_bodyCheckResult.jsp"><img src="images/surscribe.png" /> Body Check Result</a></li>
					<li><a href="user_infoModifyInput.jsp"><img src="images/account.png" /> Account Management</a>
						<ul>
						<li><a href="user_pwdModifyInput.jsp">Change password</a></li>
						<li><a href="user_infoModifyInput.jsp">Change personal info</a></li>
						</ul>
					</li>
	            </ul>
	        </div>
	        <div id="main-cont">
	        	<div id="regist_form">
	                <form action="user_pwdModifyInput.jsp" method="post" name="changepwd" onSubmit="return checkdata()">
	                	<input type="hidden" name="action" value="changepwd" />
	                    <h2>Change password</h2>
	                    <table>
	                    	<tr><td>Old Password: </td><td><input name="pwd"  type="password" onblur = "checkPassWord(this.value)"/>
	                    	<span id = "passwordErr"></span><br></td></tr>	                        
	                        <tr><td>New Password: </td><td><input name="newpwd"  type="password" onblur = "checkNewPassWord(this.value)"/>
	                        <span id = "newpasswordErr"></span><br></td></tr>
	                        <tr><td>Confirm Password: </td><td><input name="newpwd2"  type="password" onblur = "checkNewPassWord2(this.value)"/>
	                        <span id = "newpassword2Err"></span><br></td></tr>
	                        <tr><td/><td/></tr>
	                        <tr><td colspan="2" align="center"><input type="submit" value="OK! Change it!"/></td></tr>                     
	                    </table>
	                </form>
	       		</div>
	        </div>
	    </div>
	    <!-- // contents -->
	</div>
	<!-- // container -->
	<div id="footer">
		<div id="bs_stdio">
	    	©2011-2011 www.bluesky.com.mo All Rights Reserved<br/>
	    	<img src="images/bluesky_logo.png" />
	    </div>
	</div>
  </body>
</html>
